/**
 * @ClassName KP28_SameTree
 * @Description: TODO
 * @Author: JCC
 * @CreateTime: 2023/10/25 18:04
 */

/**
 * 相同树
 */
public class KP28_SameTree {
    // 测试链接：https://leetcode.cn/problems/same-tree/description/

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int val) {
            this.val = val;
        }

    }


    public boolean isSameTree(TreeNode p, TreeNode q) {
        // ①
        /*if (p == null && q != null || p != null && q == null) {
            return false;
        }*/
        // ①式可以简化为②式
        // ②
        if (p == null ^ q == null) {
            return false;
        }
        if (p == null && q == null) {
            return true;
        }
        return p.val == q.val && isSameTree(p.left,q.left) && isSameTree(p.right,q.right);
    }
}
